This sample illustrates the use of OnPortletRequestEvent to extract the user nickname property from the USER_INFO object provided by the portal server.
The sample code for this plugin can be found in the examples/interview-portlet/username-extractor directory.
The example consists of:
- An entry in portlet.xml that exposes the nickname:
<user-attribute>
<description>User Nickname</description>
<name>user.name.nickName</name>
</user-attribute>
- A Java class PortletUsernameExtractor that extracts the nickname from the Portlet Request
This class is an event handler for OnPortletRequestEvent. In the handleEvent, method, the user nickname is extracted using the following code:
Map userInfo = (Map)
event.getPortletRequest().getAttribute(PortletRequest.USER_INFO);
if (userInfo != null && !userInfo.isEmpty()) {
String nickName = (String) userInfo.get("user.name.nickName");
}
The nickname can then be stored as an attribute in the Portlet Request using the following code:
event.getPortletRequest().setAttribute("user-id", nickName);
The Oracle Policy Automation Interview Portlet by default exposes the nickname by way of portlet.xml. If other attributes need to be accessed by custom plugins, they need to be declared in portlet.xml.